package org.rambadger.command.event;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.rambadger.command.validation.UrlIdentifier;

import javax.validation.constraints.NotNull;
import java.io.Serializable;


/**
 * Event representing a new {@link org.rambadger.command.model.UserAggregate User} being registered.
 */
public class UserRegistered implements Serializable {
    private static final long serialVersionUID = -461502592876221665L;

    private final String username;
    private final String passwordHash;
    private final String emailAddress;
    private final String firstName;
    private final String lastName;

    /**
     * Instantiates a new event.
     *
     * @param username the unique username
     * @param passwordHash the password hash
     * @param emailAddress the email address
     */
    public UserRegistered(String username, String passwordHash, String emailAddress) {
        this(username, passwordHash, emailAddress, "", "");
    }

    /**
     * Instantiates a new event.
     *
     * @param username the unique username
     * @param passwordHash the password hash
     * @param emailAddress the email address
     * @param firstName the first name
     * @param lastName the last name
     */
    public UserRegistered(String username, String passwordHash, String emailAddress, String firstName, String lastName) {
        this.username = username;
        this.passwordHash = passwordHash;
        this.emailAddress = emailAddress;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    /**
     * Gets the unique username.
     *
     * @return the username
     */
    @UrlIdentifier @NotNull
    public String getUsername() {
    	return username;
    }

    /**
     * Gets password hash.
     *
     * @return the password hash
     */
    @NotNull
    public String getPasswordHash() {
        return passwordHash;
    }

    /**
     * Gets email address.
     *
     * @return the email address
     */
    @Email @NotBlank
    public String getEmailAddress() {
    	return emailAddress;
    }

    /**
     * Gets first name.
     *
     * @return the first name
     */
    @Length(max = 32) @NotNull
    public String getFirstName() {
    	return firstName;
    }

    /**
     * Gets last name.
     *
     * @return the last name
     */
    @Length(max = 32) @NotNull
    public String getLastName() {
    	return lastName;
    }

    @Override
    public String toString() {
        return "UserRegistered{" +
                "username='" + username + '\'' +
                ", passwordHash='" + passwordHash + '\'' +
                ", emailAddress='" + emailAddress + '\'' +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                '}';
    }
}